package com.yun.zf.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yun.zf.common.admin.dto.customer.CustomerBasicInfo;
import com.yun.zf.common.admin.dto.customer.CustomerListDto;
import com.yun.zf.common.admin.model.customer.CustomerBasicMo;
import com.yun.zf.common.admin.model.pact.PactPersonMo;
import com.yun.zf.common.app.domain.ZfCustomer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 客户资源表 Mapper 接口
 * </p>
 *
 * @author cj
 * @since 2021-03-30
 */
@Mapper
public interface ZfCustomerMapper extends BaseMapper<ZfCustomer> {

    @Select("<script>" +
            " SELECT phone from zf_customer c WHERE  c.city_code=#{cityCode} and c.province_code=#{proCode} and id=#{customerId}" +
            "</script>")
    public String getPhone(Long proCode, Long cityCode, Long customerId);

    @Select("<script>" +
            " \n" +
            "SELECT  c.`name`,c.phone iphone,c.certificate_type cardType ,c.certificate_no cardNo ,c.email ,c.sex, c.birthday from zf_customer c WHERE id=#{customerId}  and  c.city_code=#{cityCode} and c.province_code=#{proCode} " +
            "</script>")
    public CustomerBasicInfo getPactCustomer(Long proCode, Long cityCode, Long customerId);

    @Select("<script>" +
            "SELECT id,  c.`name`,c.phone ,c.certificate_type  ,c.certificate_no  ,c.email ,c.sex, c.birthday, c.citizenship from zf_customer c WHERE id=#{customerId}  and  c.city_code=#{cityCode} and c.province_code=#{proCode} " +
            "</script>")
    public CustomerBasicMo getBasicInfo(Long proCode, Long cityCode, Long customerId);

    @Update("<script>" +
            " UPDATE zf_customer SET space='platform' WHERE id=#{customerId} and city_code=#{cityCode} and province_code=#{proCode} " +
            "</script>")
    void pushPlatform(Long proCode, Long cityCode, Long customerId);

    @Select("<script>" +
            " SELECT c.`name`,c.id from zf_customer c  WHERE id in " +
            "<foreach item='item' index='index' collection='ids' open='(' separator=',' close=')' > " +
            "  #{item} " +
            "  </foreach>" +
            "and  city_code=#{cityCode} and province_code=#{proCode}  " +
            "</script>")
    List<CustomerListDto> getName(Long proCode, Long cityCode,List<Long> ids);
}
